package com.ahs.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Component;

/**
 * ClassName: BaseController<br>
 * Description: 基础类<br>
 * @author jiangL
 * @date: 2017年3月24日 下午3:50:41
 * @version V1.0
 * @since JDK 1.8
 */
@Component
public class BaseController {
	protected static Logger logger = Logger.getLogger(BaseController.class);
	
	@Autowired
	private DiscoveryClient discoveryClient;
	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;
	
	/**
	 * Description: 打印日志<br>
	 * @author jiangL
	 * @date: 2017年4月14日 下午1:37:18
	 * @version V1.0
	 * @since JDK 1.8
	 * @param remarks
	 */
	public void serviceInfo(String remarks){
		StringBuffer sb = new StringBuffer();
		ServiceInstance serviceInstance = discoveryClient.getLocalServiceInstance();
		sb.append(" serviceId:" + serviceInstance.getServiceId());
		sb.append(" host:" + serviceInstance.getHost());
		sb.append(" port:" + serviceInstance.getPort());
		logger.info(request.getRequestURI()+sb);
		logger.info(remarks);
	}
	
}
